from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-28 14:08:05.059991
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 28, Jan, 2021
Time: 14:08:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6333
Nobs: 185.000 HQIC: -46.5651
Log likelihood: 2093.47 FPE: 3.17482e-21
AIC: -47.2000 Det(Omega_mle): 1.97676e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.443770 0.141804 3.129 0.002
L1.Burgenland 0.125825 0.074390 1.691 0.091
L1.Kärnten -0.233288 0.060961 -3.827 0.000
L1.Niederösterreich 0.132895 0.170033 0.782 0.434
L1.Oberösterreich 0.221788 0.148693 1.492 0.136
L1.Salzburg 0.192766 0.078805 2.446 0.014
L1.Steiermark 0.095217 0.106149 0.897 0.370
L1.Tirol 0.161974 0.070958 2.283 0.022
L1.Vorarlberg -0.004180 0.066513 -0.063 0.950
L1.Wien -0.122931 0.142560 -0.862 0.389
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.496937 0.180490 2.753 0.006
L1.Burgenland 0.015983 0.094684 0.169 0.866
L1.Kärnten 0.369628 0.077592 4.764 0.000
L1.Niederösterreich 0.114225 0.216420 0.528 0.598
L1.Oberösterreich -0.150462 0.189259 -0.795 0.427
L1.Salzburg 0.192729 0.100304 1.921 0.055
L1.Steiermark 0.240904 0.135107 1.783 0.075
L1.Tirol 0.136410 0.090316 1.510 0.131
L1.Vorarlberg 0.179223 0.084658 2.117 0.034
L1.Wien -0.583835 0.181453 -3.218 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.289892 0.063988 4.530 0.000
L1.Burgenland 0.113698 0.033568 3.387 0.001
L1.Kärnten -0.025193 0.027508 -0.916 0.360
L1.Niederösterreich 0.065931 0.076726 0.859 0.390
L1.Oberösterreich 0.289418 0.067096 4.313 0.000
L1.Salzburg 0.007463 0.035560 0.210 0.834
L1.Steiermark -0.024553 0.047899 -0.513 0.608
L1.Tirol 0.092919 0.032019 2.902 0.004
L1.Vorarlberg 0.117337 0.030013 3.910 0.000
L1.Wien 0.077736 0.064329 1.208 0.227
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213414 0.073275 2.913 0.004
L1.Burgenland -0.009260 0.038440 -0.241 0.810
L1.Kärnten 0.022317 0.031501 0.708 0.479
L1.Niederösterreich 0.033185 0.087862 0.378 0.706
L1.Oberösterreich 0.390053 0.076835 5.076 0.000
L1.Salzburg 0.097301 0.040721 2.389 0.017
L1.Steiermark 0.180458 0.054851 3.290 0.001
L1.Tirol 0.041880 0.036667 1.142 0.253
L1.Vorarlberg 0.093958 0.034370 2.734 0.006
L1.Wien -0.065912 0.073666 -0.895 0.371
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.526600 0.146526 3.594 0.000
L1.Burgenland 0.075040 0.076867 0.976 0.329
L1.Kärnten 0.004636 0.062991 0.074 0.941
L1.Niederösterreich -0.011382 0.175695 -0.065 0.948
L1.Oberösterreich 0.160172 0.153645 1.042 0.297
L1.Salzburg 0.055951 0.081429 0.687 0.492
L1.Steiermark 0.109407 0.109683 0.997 0.319
L1.Tirol 0.213858 0.073321 2.917 0.004
L1.Vorarlberg 0.015732 0.068727 0.229 0.819
L1.Wien -0.137797 0.147307 -0.935 0.350
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155855 0.103754 1.502 0.133
L1.Burgenland -0.019485 0.054429 -0.358 0.720
L1.Kärnten -0.015716 0.044604 -0.352 0.725
L1.Niederösterreich 0.128491 0.124409 1.033 0.302
L1.Oberösterreich 0.400229 0.108795 3.679 0.000
L1.Salzburg -0.023574 0.057660 -0.409 0.683
L1.Steiermark -0.036320 0.077666 -0.468 0.640
L1.Tirol 0.190206 0.051918 3.664 0.000
L1.Vorarlberg 0.046565 0.048666 0.957 0.339
L1.Wien 0.180941 0.104308 1.735 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.221282 0.132459 1.671 0.095
L1.Burgenland 0.081251 0.069488 1.169 0.242
L1.Kärnten -0.048761 0.056944 -0.856 0.392
L1.Niederösterreich -0.019408 0.158828 -0.122 0.903
L1.Oberösterreich -0.089387 0.138895 -0.644 0.520
L1.Salzburg 0.032613 0.073612 0.443 0.658
L1.Steiermark 0.381221 0.099154 3.845 0.000
L1.Tirol 0.495906 0.066282 7.482 0.000
L1.Vorarlberg 0.174564 0.062130 2.810 0.005
L1.Wien -0.227816 0.133166 -1.711 0.087
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118650 0.157319 0.754 0.451
L1.Burgenland 0.014404 0.082529 0.175 0.861
L1.Kärnten -0.106583 0.067631 -1.576 0.115
L1.Niederösterreich 0.246306 0.188637 1.306 0.192
L1.Oberösterreich 0.033639 0.164963 0.204 0.838
L1.Salzburg 0.223474 0.087428 2.556 0.011
L1.Steiermark 0.114765 0.117763 0.975 0.330
L1.Tirol 0.085078 0.078722 1.081 0.280
L1.Vorarlberg 0.027056 0.073790 0.367 0.714
L1.Wien 0.253527 0.158159 1.603 0.109
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.581688 0.084722 6.866 0.000
L1.Burgenland -0.020633 0.044445 -0.464 0.642
L1.Kärnten -0.003132 0.036422 -0.086 0.931
L1.Niederösterreich -0.039776 0.101587 -0.392 0.695
L1.Oberösterreich 0.288469 0.088838 3.247 0.001
L1.Salzburg 0.018258 0.047083 0.388 0.698
L1.Steiermark 0.011712 0.063419 0.185 0.853
L1.Tirol 0.079460 0.042394 1.874 0.061
L1.Vorarlberg 0.150491 0.039738 3.787 0.000
L1.Wien -0.062777 0.085174 -0.737 0.461
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.153716 0.004703 0.208969 0.254615 0.069335 0.067038 -0.062839 0.169398
Kärnten 0.153716 1.000000 0.024551 0.196359 0.166748 -0.110691 0.178019 0.030214 0.318304
Niederösterreich 0.004703 0.024551 1.000000 0.300615 0.083862 0.216512 0.128162 0.062166 0.362379
Oberösterreich 0.208969 0.196359 0.300615 1.000000 0.299937 0.301201 0.099782 0.081233 0.124937
Salzburg 0.254615 0.166748 0.083862 0.299937 1.000000 0.157320 0.054186 0.079859 -0.015467
Steiermark 0.069335 -0.110691 0.216512 0.301201 0.157320 1.000000 0.108439 0.093008 -0.096254
Tirol 0.067038 0.178019 0.128162 0.099782 0.054186 0.108439 1.000000 0.163344 0.148088
Vorarlberg -0.062839 0.030214 0.062166 0.081233 0.079859 0.093008 0.163344 1.000000 0.080337
Wien 0.169398 0.318304 0.362379 0.124937 -0.015467 -0.096254 0.148088 0.080337 1.000000